//
//  main.swift
//  ClassDemo
//
//  Created by zhangjianyun on 17/6/27.
//  Copyright © 2017年 com.taihejiacheng. All rights reserved.
//

import Foundation

print("Hello, World!")

class Person {
    var age: Int = 18
    var name: String?
    
    
    //构造方法
    init() {
        age = 5
        name = "xiaohua"
    }
    
    init(name: String, age: Int) {
        self.age = age
        self.name = name
    }
    // 析构函数 自己调用
    deinit {
        // 可以用于释放资源等作用
    }
    func getName() -> String {
        return name!
    }
    
    func getAge() -> Int {
        return age
    }
    
    class func MaxAge() -> Int {
        return 200
    }
    
    //用类方法创建一个对象
   // class func person() -> Person {
        //return Person.type
    //}
}

func testClass()  {

    let xiaoming = Person()
    xiaoming.age = 100
    print("xiaoming is \(xiaoming)")
    print("xiaoming`s age is \(xiaoming.getAge())")
    print("xiaoming`s name is \(xiaoming.getName())")
    
    print("maxage is \(Person.MaxAge())")
    
    let xiaowang = Person(name:"xiaowang", age:28)
    print(xiaowang.age,xiaowang.name!)
    
}
testClass()
